Repository navigation
docs(skills): an async after-hook on a write event starts after the commit and is dropped on rollback; an async afterFind starts at dispatch - #34529
Conversation
…ommit and is dropped on rollback; an async afterFind starts at dispatch The Transaction row of Before vs After Hooks in skills/objectstack-data/references/data-hooks.md is now event-precise, Best Practices gains one DON'T, and two eval cases exercise both. The file pays by dropping two restatements, so its token ceiling does not move. Claude-Session: https://claude.ai/code/session_01WGufzgAt23MH7HTGSbYsVo Co-authored-by: Claude <noreply@anthropic.com>
|
domain:skills#3 · os-support-ai · session_01WGufzgtCwPzNYSczvxDEpw Contract-review-handoff: review#2 — CONTRACT_REVIEW_TIER unavailable (seat session runs the default tier, 2026-11-17T00:12Z) · head 6dbeb77 The diff touches |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head 6dbeb77 · 2026-11-17T00:14Z |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: Inputs: card #34191 (body, comments 6917374189, 6922749450, dev report 6933376061), the PR body, handoff 6933437590, the net diff against ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
S1 (should-fix) — S2 (should-fix) — eval 24, N1 (nit) — "blocking hook" is not a term this file defines: line 63 says "sync after-hook" and line 103 "Run in background". One word for the not- N2 (nit) — "outside a transaction" does not say that a lone save is inside one when the object has a blocking aborting Eval 23 holds: shape, Implemented-by: VERDICT: PASS |
… failed write A sync hook's ctx.api writes roll back with the write, so the sentence also names the caller, where the write is made. Eval 24 requires the caller-side home and no longer forbids naming the flag. Paid by one more same-file restatement cut. Claude-Session: https://claude.ai/code/session_01WGufzgAt23MH7HTGSbYsVo Co-authored-by: Claude <noreply@anthropic.com>
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head 919c3df · 2026-11-17T00:34Z |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: Delta on record 6933584271 (PASS at ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Eval 24's No must-fix. No open should-fix. N1 (nit) — from 6933584271, closed: the DON'T now says "sync hook", the word line 63 already uses, and the eval follows. N2 (nit) — from 6933584271, unchanged and accepted: "outside a transaction" still does not say when a lone save is inside the write door's unit; either reading starts the hook after the row is stored. N3 (nit) — eval 24 now has no negative assertion, so an answer that also ships the background hook passes if it mentions the caller. Accepted: the fixture is measured, not ratcheted, and the expected output states the redirect. Implemented-by: VERDICT: PASS |
|
domain:skills#3 · os-support-ai · session_01WGufzgtCwPzNYSczvxDEpw 维护者速读
席位核对Verdict: ACCEPT · head
|
Requested by Yibo Wang · project thread
Fixes #34191
Clause-②: no
Metadata-protocol: none
Skills-docs: updated here
维护者速读
objectstack-data技能的 hooks 参考里,「Before vs After」表的 Transaction 行按事件写准:写事件(afterInsert/afterUpdate/afterDelete)的async: true钩子在最外层事务提交后才启动,事务回滚(含提交失败)就不运行;afterFind的在读取派发时启动;不在事务里的立即启动。Best Practices 加一条 DON'T:不要用async: true钩子去响应被拒绝或回滚的写入;改用同步钩子(它的ctx.api写入会随该写入一起回滚),或在发起写入的调用方记录。评测夹具加两例(一正一反)。afterFind不准,也没说回滚时钩子被丢弃;AI 作者会照着写一个「写入失败时触发」的 async 钩子,而它永远不会触发。skills/objectstack-data/references/data-hooks.md的 Transaction 行(与packages/spec/src/data/hook.zod.ts的asyncTSDoc 是否一致);② 同文件 Best Practices 的 DON'T 句;③ 三处删除(「Update by id」段、body与handler表上方的引句、findOne说明的末句)是否确为重复。node scripts/check-skills-token-ratchet.mjs,预期看到skills/objectstack-data/references/data-hooks.md is 9996 tokens (ceiling 10011; headroom 15)且以 ✓ 收尾。skills/**属受管面,席位合同复审 PASS 后请批准本 PR 一次;若低风险技能臂读作 Tier S 则无,席位落地。What changes
skills/objectstack-data/references/data-hooks.md, the Transaction row of Before vs After Hooks,after*column. Before:After:
Same file, Best Practices, the DON'T paragraph gains one clause:
Both homes are the governing text's ("use a blocking hook, or record the refusal where the write is made"); the hook is called "sync", the word this file already uses for a hook that is not
async(the Can abort row).The file pays for the new text by dropping three restatements, so it shrinks (895 → 890 lines, 10003 → 9996 priced tokens) and its ceiling row does not move:
updatereads the primary key out ofdata, so the single-record form isupdate({ id, ...fieldsToChange })— e.g.update({ id: pos, status: 'filled' })." Still carried by theupdate(data, opts?)row of the method table a few lines above it in the same section ("update({ id, ...fields })— put the id insidedata"), and shown in the copy-paste example (await ctx.api.object('position').update({ id: rec.position_id, status: 'filled' });).body— the form a metadata-only runtime executes — or as the deprecated inlinehandler." Still carried by the table directly under the heading it sat beneath (Shape row: "body: { language, source, capabilities }(pure metadata)"; Status row: "Preferred for new code" against "Deprecated"), and by the schema example's comment "The logic: a sandboxed body (the inlinehandleris deprecated)".findOne's implicit "just one of them" that turns a missing predicate into a confidently wrong record." Still carried by the paragraph that opens the same note ("an absent or empty predicate does not come back asnull— it comes back as the object's first row: a real, plausible-looking record with nothing to do with what you asked for, which yourif (!row)cannot catch").skills/objectstack-data/evals/hooks-security-seeds-datasources.json: two appended cases in the file's standard shape.afterInsertonorderthat adds afulfilment_jobrow, with orders arriving in atomic batches that can roll back, plus the question whether anafterFindhook with the same flag waits for the commit. The answer is anasync: trueafterInsertwithapi.write; it starts once the outermost transaction commits and never runs on rollback, and theafterFindhook starts as the read is dispatched.payment_failurerow whenever an insert onpaymentis refused or rolled back." The answer redirects: anasynchook never sees that insert; the failure is recorded in the caller, where the write is made, and a sync hook cannot leave the row because itsctx.apiwrites roll back with the write.must_containrequires the caller-side home (caller);must_not_containis empty, since a correct answer names the flag the way the skill does..changeset/34191-skills-async-hook-commit.md:@objectstack/skillspatch.Line budget. The order gave +12 net lines across
skills/**. The seat ruled (answer A in the card thread) that the +12 reads on priced teaching text and that eval fixtures are reported separately, since they are outside the ratchet's priced population (ruling record 6513306068). Readings: teaching text −5 lines (+7 / −12), eval fixture +20 lines (two cases of 10 lines each, the shape every case in the file has), net +15 acrossskills/**.Authoring tier:
dispatch-gates --tieranswers MANDATORY CONTRACT_REVIEW_TIER forskills/**(clause ①, no one-line exit). This card thread is served at that tier (Served-tier: CONTRACT_REVIEW_TIER, read from the session record), so the diff was authored in the thread itself.Tests
No package source changes, so there is no package test to run. The two eval cases are fixtures (measured, not ratcheted) and are self-consistent: every
must_containstring appears in its case'sexpected_output, nomust_not_containstring does, and the 24 ids in the file are distinct (checked by script on919c3dfb).check:skill-examplestype-checks the marked code blocks of the edited file: "347 prose examples type-check across 3 surface(s)", exit 0.Size readings, before (merge base
9e6fee19) and after (919c3dfb)references/data-hooks.mdlines / bytesevals/hooks-security-seeds-datasources.jsonlines / bytes / tokens (not ratcheted)skills/*/SKILL.md, lines summedNo
SKILL.mdis touched. The after column is the token ratchet's own print on919c3dfb; the before column is that print less this diff's measured deltas (−7 priced, +537 eval).Acceptance notes
The engine behaviour was confirmed from code on
9e6fee19before any text was written. It agrees with the card and with the governing text (theasyncTSDoc inpackages/spec/src/data/hook.zod.tsandcontent/docs/automation/hooks.mdx, section "async: trueafter hooks run after the commit").(a) A write event's async after-hook waits for the outermost commit, and is dropped on rollback or a failed commit
packages/objectql/src/unit-detach.ts,UNIT_SETTLED_EVENTSandwaitsForUnitCommit(lines 104-109):packages/objectql/src/hook-wrappers.ts, the fire-and-forget branch of the declarative wrapper (line 540) hands that answer to the detached run, and line 542 reads the dropped case:unit-detach.ts,runOutsideOpenUnitsOnCommit(lines 196-216) queues the run on the open unit, started on commit and answeredUNIT_ROLLED_BACKwithout running on drop:packages/objectql/src/engine-transactions-section.ts,TransactionsSectionFacet.transaction: the driver commit is inside thetry, so a failed commit lands in thecatch, which drops the queue before rolling back (line 117); the queue is started only after the commit returned (line 137):Outermost: a nested
transaction()findsambient?.transaction(line 72), joins it withowned: falseand opens no queue of its own, so only the outer unit's outcome settles the run.ScopedContext's transaction (engine-scoped-context.tslines 260 and 268) and thebeginTransactiontrio (settleTrioCommitQueue, lines 348 and 354) settle the same way.Pins:
packages/objectql/src/engine-scoped-transaction-late-write.test.ts, the describe "an async after-hook fired inside a unit runs on its commit, never on its rollback" (line 460), among them "engine.transaction() rolls back: the hook never starts and writes nothing" and "nested: an inner ctx.api.transaction(fn) that returns is no commit, and the outer rollback drops the hook".(b) An async afterFind starts at dispatch; outside a unit every async after-hook starts at once
afterFindis not inUNIT_SETTLED_EVENTS, sowaitsForUnitCommit('afterFind')isfalseandrunDetachedHookruns the body at once, outside the open units (unit-detach.ts,runDetachedHookandrunOutsideOpenUnits). The module doc says why: "It does not undo a read: the rowsafterFindsaw were already returned to the caller, so anasyncafterFindrun starts at dispatch, outside the units".Outside a unit:
runOutsideOpenUnitsOnCommitline 203,if (!queue) return runOutsideOpenUnits(txStore, threaded, body);.Pins in the same test file: "afterFind inside engine.transaction() that commits: a read's async hook starts at dispatch, in the unit's lifetime, not after the commit" (line 619), "afterFind inside engine.transaction() that rolls back: the read's async hook still runs, outside the unit" (line 634), "CONTROL outside any unit: the hook starts at dispatch, before the write returns, unchanged" (line 664).
Notes, none filed:
ctx.apiwrites roll back with the write (contract review 6933584271, S1 and N1). Eval 24 requires the caller-side home and forbids nothing (S2).after*hook or one with acondition(the review's N2); either reading starts the hook after the row is stored, so the row is left as it is.data-hooks.mdis left at 10011 (headroom now 15). Lowering it is an edit toscripts/check-skills-token-ratchet.mjs, outside this card's file surface.Verification
Derived gates on
919c3dfb: 47 derived, 46 run and exit 0, 1 NOT MEASURED locallynode scripts/pm/dispatch-gates.mjs --commandslisted the same 47 commands as on the first head (3 paths vs merge base9e6fee19e). Each ran serially with its exit code recorded before any pipe asCMD :: exit N, then reconciled:NOT MEASURED:
pnpm check:dual-build-cjs-loads, exit 3 "PREREQUISITE NOT MET" (it reads a full build, and this diff changes no package source). CI's Lint lanes run it on this PR.check:dts-closure,check:lean-entry-closureandcheck:sourcemap-no-sources-contentexit 0 here against the 44 packages this worktree has built (the lint and client closures, built under the verify lock), not a full build; CI's run is the full one.Also run, each exit 0:
pnpm --filter @objectstack/spec run check:skill-examples("347 prose examples type-check across 3 surface(s)"),pnpm --filter @objectstack/spec run check:skill-docs.Token ratchet: "57 authored bundle file(s) within their ceilings; 10 generator-owned file(s) and 29 eval fixture(s) measured, not ratcheted";
skills/objectstack-data/references/data-hooks.md is 9996 tokens (ceiling 10011; headroom 15).First head
6dbeb77d: 47 derived, 43 exit 0, 4 NOT MEASURED (no build yet).Governed-surface reading
node scripts/pm/check-governed-merges.mjs --branch HEADon the first head6dbeb77d: "2 of 3 path(s) hit the register" (skills/**×2; the changeset is not on the register), landing tier H on a path list alone; the low-risk skills arm reads NOT MEASURED until--prcan read the pull request. Size on919c3dfb: 49 changed lines (+37 / −12), under the 3000 human-merge threshold. This PR stays a draft; the seat reviews and lands.Base: the branch is cut from
9e6fee19.origin/mainwas atec6b5fd3when this PR opened; the commits in between touch no file of this diff (skills/objectstack-data/**, the ratchet script), andgit merge-treereports a clean merge, somainwas not merged in.🤖 Generated with Claude Code
https://claude.ai/code/session_01WGufzgAt23MH7HTGSbYsVo